package cn.hadron.ssh.action.admin;
import java.time.LocalDateTime;
import java.util.List;
import cn.hadron.ssh.bean.Article;
import cn.hadron.ssh.bean.Channel;
import cn.hadron.ssh.service.*;
import com.opensymphony.xwork2.ActionSupport;

public class ArticleChannelAction extends ActionSupport {
	private int id;
	private String content;
	private Article article;
	private List<Channel> clist;
	private String message;
	private ArticleService as;
	private ChannelService cs;
	//添加新文章
	public String add() throws Exception {
		if(article==null){//准备Channel数据
			clist=cs.findAllChannel();
			return INPUT;
		}
		article.setAddtime(LocalDateTime.now().toString());
		article.setContent(content);
		as.addArticle(article);
		Channel c=cs.findChannel(article.getChannel().getId());
		article.getChannel().setName(c.getName());
		message = "发布成功！";
		return SUCCESS;
	}
	//修改文章
	public String edit() throws Exception {
		if(article==null){//准备编辑数据
			article=as.findArticle(id);
			clist=cs.findAllChannel();
			return INPUT;
		}
		article.setAddtime(LocalDateTime.now().toString());
		article.setContent(content);
		as.modifyArticle(article);
		Channel c=cs.findChannel(article.getChannel().getId());
		article.getChannel().setName(c.getName());
		message="更新成功！";
		return SUCCESS;
	}
	
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	public String getContent() {
		return content;
	}
	public void setContent(String content) {
		this.content = content;
	}
	public Article getArticle() {
		return article;
	}
	public void setArticle(Article article) {
		this.article = article;
	}
	public String getMessage() {
		return message;
	}
	public void setMessage(String message) {
		this.message = message;
	}
	public List<Channel> getClist() {
		return clist;
	}
	public void setClist(List<Channel> list) {
		this.clist = list;
	}
	public ArticleService getAs() {
		return as;
	}
	public void setAs(ArticleService as) {
		this.as = as;
	}
	public ChannelService getCs() {
		return cs;
	}
	public void setCs(ChannelService cs) {
		this.cs = cs;
	}
}
